package com.usian.comment.controller.v1;

import com.usian.comment.service.CommentService;
import com.usian.comment.vo.CommentVo;
import com.usian.common.dtos.ResponseResult;
import com.usian.model.comment.dtos.CommentDto;
import com.usian.model.comment.dtos.CommentLikeDto;
import com.usian.model.comment.dtos.CommentSaveDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * 评论web层代码
 */
@RestController
@RequestMapping("/api/v1/comment")
public class CommentController {

    @Autowired
    private CommentService commentService;

    /**
     * 发表评论
     */
    @PostMapping("/save")
    public ResponseResult saveComment(@Valid @RequestBody CommentSaveDto dto){
        commentService.saveComment(dto);
        return ResponseResult.ok();
    }

    /**
     * 查询评论列表
     */
    @PostMapping("/load")
    public ResponseResult<List<CommentVo>> loadComment(@Valid @RequestBody CommentDto dto){
        List<CommentVo> list = commentService.loadComment(dto);
        return ResponseResult.ok(list);
    }

    /**
     * 点赞评论
     * @param dto
     * @return
     */
    @PostMapping("/like")
    public ResponseResult likeComment(@RequestBody CommentLikeDto dto){
        commentService.likeComment(dto);
        return ResponseResult.ok();
    }

}
